package com.heima.review.controller;

import com.heima.common.dtos.ResponseResult;
import com.heima.model.comment.dtos.CommentLikeDto;
import com.heima.model.comment.dtos.CommentPageQueryDTO;
import com.heima.model.comment.dtos.CommentSaveDto;
import com.heima.model.review.CommentRepaySaveDto;
import com.heima.model.review.dtos.ReviewPageDTO;
import com.heima.review.entity.AdComment;
import com.heima.review.service.AdCommentLikeService;
import com.heima.review.service.AdCommentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
public class ReviewController {

    @Autowired
    private AdCommentService commentService;
    @Autowired
    private AdCommentLikeService likeService;

    /**
     * feign调用，根据评论id删除评论
     */
    @DeleteMapping("/api/v1/comment/del_comment/{commentId}")
    public ResponseResult delComment(@PathVariable("commentId") Long commentId) {
        commentService.delComment(commentId);
        return ResponseResult.ok();
    }

    /**
     * feign调用，根据回复id删除回复
     */
    @DeleteMapping("/api/v1/comment/del_comment_repay/{commentRepayId}")
    public ResponseResult delCommentRepay(@PathVariable("commentRepayId") Long replyId) {
        commentService.delCommentRepay(replyId);
        return ResponseResult.ok();
    }



    /**
     * 作者回复评论
     *
     * @param dto
     * @return
     */
    @PostMapping("/api/v1/comment/manage/comment_repay")
    public ResponseResult commentRepay(@RequestBody CommentRepaySaveDto dto) {
        commentService.commentRepay(dto);
        return ResponseResult.ok();
    }


    /**
     * 评论和回复查询所有
     *
     * @param dto
     * @return
     */
    @PostMapping(" /api/v1/comment/manage/list")
    public ResponseResult manageList(@RequestBody CommentPageQueryDTO dto) {
        return ResponseResult.ok(commentService.getPage(dto));
    }




    /**
     * 文章评论-点赞
     */
    @PostMapping("/api/v1/comment/like")
    public ResponseResult like(CommentLikeDto dto) {
        Integer likes = likeService.like(dto);
        return ResponseResult.ok(likes);
    }

    /**
     * 文章评论-点赞
     */
    @PostMapping("/api/v1/comment/manage/like")
    public ResponseResult manageLike(CommentLikeDto dto) {
        Integer likes = likeService.like(dto);
        return ResponseResult.ok(likes);
    }



    /**
     * 文章查询列表
     *
     * @param dto
     * @return
     */
    @PostMapping("/api/v1/comment/load")
    public ResponseResult load(@RequestBody ReviewPageDTO dto) {
        return ResponseResult.ok(commentService.load(dto));
    }



    /**
     * 发布评论
     * @param dto
     * @return
     */
    @PostMapping("/api/v1/comment/save")
    public ResponseResult saveComment(@RequestBody CommentSaveDto dto){
        commentService.saveComment(dto);
        return ResponseResult.ok();
    }

    /**
     * feign,调用根据文章id删除评论
     * @param articleId
     */
    @DeleteMapping("/api/v1/comment/del_comment/{articleId}")
    public void delCommentByArtilceId(@PathVariable("articleId") Long articleId){
        commentService.delCommentByArtilceId(articleId);
    }
}
